home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_01 / comm5.c < prev    next >
C/C++ Source or Header  |  1993-12-06  |  30KB  |  982 lines

  1. /***********************************************************************/
  2. /* COMM5.C - Commands T-Z                                              */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1993 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Header: C:\THE\RCS\comm5.c 1.4 1993/09/01 16:25:46 MH Interim MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. /*#define DEBUG 1*/
  51.  
  52. /*-------------------------- external data ----------------------------*/
  53. extern LINE *next_line,*curr_line;
  54. extern VIEW_DETAILS *vd_current,*vd_first;
  55. extern char current_screen;
  56. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  57. extern char current_file;         /* pointer to current file */
  58. extern WINDOW *foot,*error_window;
  59. extern bool error_on_screen;
  60. extern char *rec;
  61. extern unsigned short rec_len;
  62. extern char *cmd_rec;
  63. extern unsigned short cmd_rec_len;
  64. extern char mode_insert;        /* defines insert mode toggle */
  65. /*man-start*********************************************************************
  66. COMMAND
  67.      tabcmd - switch windows (main/prefix command) for the current file
  68.  
  69. SYNTAX
  70.      TABCmd
  71.      ** effective only if bound to a key **
  72.  
  73. DESCRIPTION
  74.      The TABCMD command switches the focus of the editor from the
  75.      main or prefix windows to the command line and vice versa, depending
  76.      on which window is currently active.
  77.  
  78. COMPATIBILITY
  79.      XEDIT: Equivalent of CURSOR HOME.
  80.      KEDIT: Equivalent of CURSOR HOME.
  81.  
  82. SEE ALSO
  83.      tabpre
  84.  
  85. STATUS
  86.      Complete. Will be replaced by CURSOR HOME in the future.
  87. **man-end**********************************************************************/
  88. #ifdef PROTO
  89. int Tabcmd(char *params)
  90. #else
  91. int Tabcmd(params)
  92. char *params;
  93. #endif
  94. /***********************************************************************/
  95. {
  96. /*--------------------------- local data ------------------------------*/
  97.  char last_win;
  98.  unsigned short x,y;
  99. /*--------------------------- processing ------------------------------*/
  100. #ifdef TRACE
  101.  trace_function("comm5.c:   Tabcmd");
  102. #endif
  103.  last_win = CURRENT_VIEW->previous_window;
  104.  CURRENT_VIEW->previous_window =
  105.               CURRENT_VIEW->current_window;
  106.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  107.     {
  108.      post_process_line(CURRENT_VIEW->focus_line);
  109.      CURRENT_VIEW->current_window = WINDOW_COMMAND;
  110.      wmove(CURRENT_WINDOW,0,0);
  111.     }
  112.  else
  113.     {
  114.      pre_process_line(CURRENT_VIEW->focus_line);
  115.      CURRENT_VIEW->current_window = last_win;
  116.      getyx(CURRENT_WINDOW,y,x);
  117.      y = get_row_for_focus_line(CURRENT_VIEW->current_row,
  118.                                 CURRENT_VIEW->focus_line,
  119.                                 CURRENT_VIEW->current_line);
  120.      wmove(CURRENT_WINDOW,y,x);
  121.     }
  122. #ifdef TRACE
  123.  trace_return();
  124. #endif
  125.  return(RC_OK);
  126. }
  127. /*man-start*********************************************************************
  128. COMMAND
  129.      tabpre - switch windows (main/prefix) for the current file
  130.  
  131. SYNTAX
  132.      TABPre
  133.      ** effective only if bound to a key **
  134.  
  135. DESCRIPTION
  136.      The TABPRE command switches the focus of the editor from the
  137.      main window to the prefix window and vice versa, depending
  138.      on which window is currently active.
  139.  
  140. COMPATIBILITY
  141.      XEDIT: N/A
  142.      KEDIT: Equivalent of SOS LEFTEDGE and SOS PREFIX
  143.  
  144. SEE ALSO
  145.      tabcmd
  146.  
  147. STATUS
  148.      Complete.
  149. **man-end**********************************************************************/
  150. #ifdef PROTO
  151. int Tabpre(char *params)
  152. #else
  153. int Tabpre(params)
  154. char *params;
  155. #endif
  156. /***********************************************************************/
  157. {
  158. /*--------------------------- local data ------------------------------*/
  159.  char last_win;
  160.  unsigned short y,x;
  161. /*--------------------------- processing ------------------------------*/
  162. #ifdef TRACE
  163.  trace_function("comm5.c:   Tabpre");
  164. #endif
  165. /*---------------------------------------------------------------------*/
  166. /* If the cursor is in the command line or there is no prefix on, exit.*/
  167. /*---------------------------------------------------------------------*/
  168.  if (CURRENT_VIEW->current_window == WINDOW_COMMAND
  169.  ||  !CURRENT_VIEW->prefix)
  170.    {
  171. #ifdef TRACE
  172.     trace_return();
  173. #endif
  174.     return(RC_OK);
  175.    }
  176.  
  177.  getyx(CURRENT_WINDOW,y,x);
  178.  
  179.  last_win = CURRENT_VIEW->previous_window;
  180.  CURRENT_VIEW->previous_window =
  181.               CURRENT_VIEW->current_window;
  182.  if (CURRENT_VIEW->current_window == WINDOW_MAIN)
  183.    {
  184.     post_process_line(CURRENT_VIEW->focus_line);
  185.     CURRENT_VIEW->current_window = WINDOW_PREFIX;
  186.    }
  187.  else
  188.    {
  189.     pre_process_line(CURRENT_VIEW->focus_line);
  190.     CURRENT_VIEW->current_window = WINDOW_MAIN;
  191.    }
  192.  wmove(CURRENT_WINDOW,y,0);
  193. #ifdef TRACE
  194.  trace_return();
  195. #endif
  196.  return(RC_OK);
  197. }
  198. /*man-start*********************************************************************
  199. COMMAND
  200.      text - simulate keyboard entry of characters
  201.  
  202. SYNTAX
  203.      TEXT text
  204.  
  205. DESCRIPTION
  206.      The TEXT command simulates the entry of characters from the
  207.      keyboard. This command is actually called when you enter text
  208.      from the keyboard.
  209.  
  210. COMPATIBILITY
  211.      XEDIT: N/A
  212.      KEDIT: Compatible.
  213.             Does not allow leading or trailing spaces in text (at the
  214.             moment)
  215.  
  216. STATUS
  217.      Complete.
  218. **man-end**********************************************************************/
  219. #ifdef PROTO
  220. int Text(char *params)
  221. #else
  222. int Text(params)
  223. char *params;
  224. #endif
  225. /***********************************************************************/
  226. {
  227. /*------------------------- external data -----------------------------*/
  228.  extern bool extended_display_mode;
  229.  extern bool CMDARROWSTABLRx;
  230.  extern bool prefix_changed;
  231.  extern char *pre_rec;
  232.  extern unsigned short pre_rec_len;
  233. /*--------------------------- local data ------------------------------*/
  234.  register int i;
  235.  char real_key;
  236.  chtype chtype_key;
  237.  unsigned short y,x;
  238.  bool save_CMDARROWSTABLRx;
  239.  int len_params;
  240.  int rc;
  241. /*--------------------------- processing ------------------------------*/
  242. #ifdef TRACE
  243.  trace_function("comm5.c:   Text");
  244. #endif
  245. /*---------------------------------------------------------------------*/
  246. /* If no parameters, return without doing anything.                    */
  247. /*---------------------------------------------------------------------*/
  248.  save_CMDARROWSTABLRx = CMDARROWSTABLRx;
  249.  if (CURRENT_VIEW->hex == ON)
  250.    {
  251.     if ((len_params = convert_hex_strings(params)) == (-1))
  252.       {
  253.        display_error(32,(char *)"");
  254. #ifdef TRACE
  255.        trace_return();
  256. #endif
  257.        return(RC_INVALID_OPERAND);
  258.       }
  259.    }
  260.  else
  261.    len_params = strlen(params);
  262.  for (i=0;i<len_params;i++)
  263.    {
  264.     real_key = case_translate((char)*(params+i));
  265.     chtype_key = (chtype)(real_key & A_CHARTEXT);
  266.     switch(CURRENT_VIEW->current_window)
  267.       {
  268.        case WINDOW_MAIN:
  269.             if (CURRENT_VIEW->focu